 
package com.zdkj.subway.stm.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zdkj.subway.stm.entity.SwStElectronicReceipt;
import com.zdkj.subway.stm.entity.SwStElectronicReceiptDetails;
import com.zdkj.subway.stm.mapper.SwStElectronicReceiptDetailsMapper;
import com.zdkj.subway.stm.service.SwStElectronicReceiptDetailsService;
import com.zdkj.subway.stm.util.JdbcUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.util.StringUtil;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 
 *
 * @author songtuo
 * @date 2020-07-13 13:34:08
 */
@Service
public class SwStElectronicReceiptDetailsServiceImpl extends ServiceImpl<SwStElectronicReceiptDetailsMapper, SwStElectronicReceiptDetails> implements SwStElectronicReceiptDetailsService {


    @Override
    public boolean updateElectronic(String ids, String ticketTransferAmount) {
        if ( ids==null) {
            return false;
        }
        try {
            Integer relationId=0 ;
            BigDecimal sumMoney = new BigDecimal(0);
            List list = (List)JSON.parse(ids);
            if(list!=null && !list.isEmpty()){
                for(int i=0;i<list.size();i++){
                    String obj = String.valueOf(list.get(i));
                    Map map = (Map)JSON.parse(obj);
                    Integer id = (Integer)map.get("id");
                    String strMoney = String.valueOf(map.get("ticketTransferAmount"));
                    relationId = (Integer)map.get("relationId");
                    BigDecimal money= new BigDecimal(0);
                    if(StringUtils.isNotEmpty(strMoney)){
                        money = new BigDecimal(strMoney);
                    }
                    sumMoney = sumMoney.add(money);
                    JdbcUtil.exeSqlCrud("update sw_st_electronic_receipt_details set ticket_Transfer_Amount=" + money + " where id=" + id);

                }
                JdbcUtil.exeSqlCrud("update sw_st_electronic_receipt set TOTAL_TRANSFER_AMOUNT=" + sumMoney + " where id=" + relationId);
            }

            //{"ids":";54;55","ticketTransferAmount":";2;9"}


        }catch (Exception e){
        }
        return true;
    }
}
